<template>
  <div class="connection-recommend">
    <div class="chart">
      <div class="auto-join-recommend">
        <div class="legend-color">
          <span class="header-score-legend">字段名推荐</span>
          <span class="value-score-legend">字段值推荐</span>
        </div>
        <div class="recommend-clause">
          <template
            v-for="(clause, index) in edgeConfigData.autoJoinRecommendation"
          >
            <div
              v-if="index < 20"
              :key="index"
              class="clause-item"
              title="点击应用"
              @click="useCurrentRecommendation(clause)"
            >
              <!-- 推荐的字句 -->
              <div class="clause-text">
                <span
                  class="clause-field clause-field-left"
                  :style="{ color: leftColor }"
                  :title="clause.leftHeaderName"
                  >{{ clause.leftHeaderName }}</span
                >
                <span class="relation">=</span>
                <span
                  class="clause-field clause-field-right"
                  :style="{ color: rightColor }"
                  :title="clause.rightHeaderName"
                  >{{ clause.rightHeaderName }}</span
                >
              </div>
              <popover-coefficient-bar
                class="clause-bar"
                :score="clause.score"
                :width="300"
                :header-score="clause.headerScore"
                :value-score="clause.valueScore"
              />
            </div>
          </template>
          <div
            v-if="
              edgeConfigData.autoJoinRecommendation &&
              edgeConfigData.autoJoinRecommendation.length === 0
            "
            class="empty-recommendation"
          >
            -- 无推荐 --
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { Component, Prop, Vue, Watch } from 'vue-property-decorator'
import PopoverCoefficientBar from '@/components/studio/data/set-params/auto-join/PopoverCoefficientBar.vue'
// import {OperatorGroupIconBackGround, DataIcon} from '@/components/studio/data/graph-compoments/node-icon-util'

@Component({
  components: {
    PopoverCoefficientBar,
  },
})
export default class ConnectionRecommend extends Vue {
  @Prop({ default: () => ({}) }) edgeConfigData!: any // 配置信息
  @Prop({ default: () => ({}) }) data!: any
  @Prop({ default: '' }) leftHeaderName!: any
  @Prop({ default: '' }) rightHeaderName!: any

  // TODO
  @Watch('leftHeaderName')
  public leftChange() {
    console.log('left change')
  }

  @Watch('rightHeaderName')
  public rightChange() {
    console.log('right change')
  }

  public get leftColor() {
    return this.data?.sourceNode.style.fill
  }

  public get rightColor() {
    return this.data?.targetNode.style.fill
  }

  public useCurrentRecommendation(clause: any) {
    this.$emit('select-clause', clause)
  }
}
</script>
<style lang="less" scoped>
.connection-recommend {
  width: 100%;
}

.chart {
  border: 2px solid #eee;
  height: 90%;
  width: 100%;
}

.auto-join-recommend {
  overflow: hidden;
  padding: 16px;
  width: 100%;

  // 推荐的 bar 图例
  .legend-color {
    align-items: center;
    cursor: pointer;
    display: flex;
    height: 22px;
    justify-content: center;
    margin-bottom: 16px;

    .header-score-legend {
      margin: 0 8px 0 18px;
      position: relative;

      &::before {
        background-color: #8289dd;
        content: '';
        height: 8px;
        left: -14px;
        position: absolute;
        top: 7px;
        width: 10px;
      }
    }

    .value-score-legend {
      margin: 0 8px 0 20px;
      position: relative;

      &::before {
        background-color: #ced0ed;
        content: '';
        height: 8px;
        left: -14px;
        position: absolute;
        top: 7px;
        width: 10px;
      }
    }
  }

  // 推荐的子句
  .recommend-clause {
    width: 100%;

    .clause-item {
      align-items: center;
      cursor: pointer;
      display: flex;
      height: 30px;
      // justify-content: space-between;
      justify-content: center;
      margin: 10px 0;

      /* 连接关系 */

      .clause-text {
        display: flex;
        font-size: 16px;
        justify-content: space-between;
        margin-right: 16px;
        text-align: center;
        width: 150px;
        // 498 - 300

        .clause-field {
          overflow: hidden;
          text-align: right;
          text-overflow: ellipsis;
          white-space: nowrap;
          width: 40%;
        }

        .clause-field-right {
          text-align: left;
        }

        .relation {
          color: #7e785d;
          text-align: center;
          width: 20%;
        }
      }

      /* 添加 icon */

      .add-recommend-clause {
        font-size: 16px;
        margin-left: 6px;
        opacity: 0;
      }

      &:hover {
        background-color: #eaeaea;

        .add-recommend-clause {
          opacity: 1;
        }
      }
    }

    // 没有推荐
    .empty-recommendation {
      height: 54px;
      line-height: 54px;
      text-align: center;
    }
  }

  .recommend-coefficient {
    z-index: 10;
  }
}
</style>
